using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace OsdmSoftware.CommonLibrary
{
    class HintLabel: Control, IDropDownControl
    {
        int optimalWidth;
        int optimalHeight;
        public HintLabel(Control parentControl, string text)
        {
            Graphics gr = parentControl.CreateGraphics();
            SizeF size = gr.MeasureString(text, parentControl.Font);
            optimalWidth = (int) size.Width + 10;
            optimalHeight = (int) size.Height + 10;
            gr.Dispose();
            this.Text = text;
            this.Font = parentControl.Font;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.DrawRectangle(new Pen(this.ForeColor), 0, 0, this.Width - 1, this.Height - 1);
            e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), 5, 5);
            base.OnPaint(e);
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (CloseParentDropDown != null)
                CloseParentDropDown(this, EventArgs.Empty);
            base.OnMouseDown(e);
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
        }

        public event EventHandler CloseParentDropDown;

        public System.Drawing.Size GetOptimalSize(int maxWidth, int maxHeight)
        {
            return new Size(optimalWidth, optimalHeight);
        }

        public void CloseDropDown()
        {
        }

        public void ReleaseResources()
        {
        }

        public void Initialize()
        {
        }

        public System.Windows.Forms.Control Control
        {
            get { return this; }
        }

        public bool DisposeWithForm
        {
            get { return true; }
        }

        public float Area
        {
            get { return optimalWidth * optimalHeight; }
        }
    }
}
